package com.cen.service;

import com.cen.dao.BaseDao;
import com.cen.dao.user.IUserDao;
import com.cen.dao.user.IUserDaoImpl;
import com.cen.domain.User;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author : cen
 * @date : 2020/5/18 8:36
 */
public class UserServiceImpl implements IUserService {
    private IUserDao iUserDao;

    public UserServiceImpl() {
        this.iUserDao = new IUserDaoImpl();
    }

    @Override
    public User login(String userCode, String userPassword) {
        Connection connection = null;
        User user = null;
        try {
            connection = BaseDao.getConnection();
            user = iUserDao.getLoginUser(connection, userCode);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            BaseDao.closeResource(connection, null, null);

        }
        if (user != null) {
            if (!user.getUserPassword().equals(userPassword)) {
                user = null;
            }

        }
        return user;
    }
}